(in-package #:coalton-native-tests)

(named-readtables:in-readtable coalton:coalton)

(define-test test-rounding ()
  (is (== 0 (floor 0.1)))
  (is (== 1 (ceiling 0.1)))
  (is (== 0 (round 0.1)))
  (is (== 0 (math:round-half-up 0.1)))
  (is (== 0 (math:round-half-down 0.1)))
  (is (== 0 (math:truncate 0.1)))

  (is (== -1 (floor -0.1)))
  (is (== 0 (ceiling -0.1)))
  (is (== 0 (round -0.1)))
  (is (== 0 (math:round-half-up -0.1)))
  (is (== 0 (math:round-half-down -0.1)))
  (is (== 0 (math:truncate -0.1)))
  
  (is (== 0 (floor 0.0)))
  (is (== 0 (ceiling 0.0)))
  (is (== 0 (round 0.0)))
  (is (== 0 (math:round-half-up 0.0)))
  (is (== 0 (math:round-half-down 0.0)))
  (is (== 0 (math:truncate 0.0)))

  (is (== 1 (math:round-half-up 0.5)))
  (is (== 0 (math:round-half-down 0.5)))
  (is (== 0 (math:round-half-up -0.5)))
  (is (== -1 (math:round-half-down -0.5)))

  (is (== (lisp Integer () (cl:round 2.5)) (round 2.5)))
  (is (== (lisp Integer ()  (cl:round -2.5)) (round -2.5)))
  (is (== (lisp Integer ()  (cl:round 1.5)) (round 1.5)))
  (is (== (lisp Integer ()  (cl:round -1.5)) (round -1.5)))
  (is (== (lisp Integer ()  (cl:round 0.5)) (round 0.5)))
  (is (== (lisp Integer ()  (cl:round -0.5)) (round -0.5))))
